package microcredit.gui.table.impl;

import java.awt.Color;

import javax.swing.ImageIcon;

import microcredit.gui.table.EnumBeanTableModel;
import microcredit.gui.util.FormatUtilities;
import microcredit.model.MemberToGroup;
import microcredit.model.domain.Status;

enum MemberGroupHistoryColumn {
	COLUMN_GROUP,
	COLUMN_FROM,
	COLUMN_TO;
}
public class MemberGroupHistoryTableModel extends
		EnumBeanTableModel<MemberToGroup, MemberGroupHistoryColumn> {

	@Override
	protected Object getValue(MemberToGroup o, MemberGroupHistoryColumn column) {
		switch (column) {
		case COLUMN_GROUP : return o.getMemberGroup() == null ? "<< No group >>" : o.getMemberGroup().getFullName();
		case COLUMN_FROM : return FormatUtilities.formatDate(o.getSince());
		case COLUMN_TO : return o.getUntil() == null ? "Now" : FormatUtilities.formatDate(o.getUntil());
		}
		return null;
	}
	
	private final Color lightGreen = Color.decode("#baff7d");
	
	@Override
	protected Color getBackground(MemberToGroup o,
			MemberGroupHistoryColumn column) {
		if (o.getStatus().equals(Status.A)) {
			return lightGreen;
		} else {
			return Color.WHITE;
		}
	}
	
	@Override
	protected int getWidth(MemberGroupHistoryColumn column) {
		switch (column) {
		case COLUMN_GROUP : return 300;
		case COLUMN_FROM : return 100;
		case COLUMN_TO : return 100;
		}
		return -1;
	}
	
	@Override
	protected ImageIcon getRowIcon(MemberToGroup o) {
		String icon = "";
		
		if (o.getMemberGroup() == null) {
			icon = "users3_delete";
		} else {
			icon = "users3_edit";
		}
		
		return new ImageIcon(MemberGroupHistoryTableModel.class
				.getResource("/microcredit/icons/x16/"+icon+".png"));
	}
	
	
	@Override
	protected boolean isBold(MemberToGroup o, MemberGroupHistoryColumn column) {
		if (o.getStatus().equals(Status.A)) {
			return true;
		} 
		return super.isBold(o, column);
	}
	
	@Override
	protected String getName(MemberGroupHistoryColumn column) {
		switch (column) {
		case COLUMN_GROUP : return "Group";
		case COLUMN_FROM : return "From";
		case COLUMN_TO : return "Until";
		}
		return null;
	}

}